package com.itheima.wms.controller;

import com.itheima.wms.pojo.WareHouse;
import com.itheima.wms.pojo.WareHousePageRequest;
import com.itheima.wms.service.WareHouseService;
import com.itheima.wms.utils.PageBean;
import com.itheima.wms.utils.Result;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*
仓库管理
* */
@RequiredArgsConstructor
@RestController
@RequestMapping("/warehouse")
public class WareHouseController {

    private final WareHouseService wareHouseService;

    @PostMapping
    public Result addWareHouse(@RequestBody WareHouse wareHouse) {
        wareHouseService.addWareHouse(wareHouse);
        return Result.success("插入成功");
    }

    @GetMapping("/page")
    public Result queryWareHouseOnCondationAndPage(WareHousePageRequest wareHousePageRequest) {
        PageBean pageBean = wareHouseService.queryWareHouseOnCondationAndPage(wareHousePageRequest);
        return Result.success(pageBean);
    }

    @GetMapping("/{id}")
    public Result queryWareHouseById(@PathVariable Integer id) {
        WareHouse wareHouse = wareHouseService.queryWareHouseById(id);
        return Result.success(wareHouse);
    }

    @PutMapping
    public Result updateWareHouse(@RequestBody WareHouse wareHouse) {
        wareHouseService.updateWareHouse(wareHouse);
        return Result.success("修改成功");
    }


    @DeleteMapping
    public Result deleteWareHouse(Integer ids) {
        wareHouseService.deleteWareHouse(ids);
        return Result.success("删除成功");
    }

    @GetMapping("/list")
    public Result queryAllWareHousees() {
        List<WareHouse> wareHouses = wareHouseService.queryAllWareHousees();
        return Result.success(wareHouses);
    }
}
